import {
  NativeModules,
  Platform,
  Image,
}
  from 'react-native'

const { ReadImageDataManager } = NativeModules

export default class ReadImageManager {

  static readImage (imageInfo: Object): Promise {
    return ReadImageDataManager.readImage(imageInfo)
  }

  static readImages (imageInfos: Array): Promise {
    return ReadImageDataManager.readImages(imageInfos)
  }

  static readPictureDegree (source: ImageSource | String): Promise {

    if (typeof source === 'string') {
      if (Platform.OS === 'ios') {
        let imageSource = Image.resolveAssetSource({ uri: source })
        return ReadImageDataManager.readPictureDegree(imageSource)
      }else{//安卓
        return ReadImageDataManager.readPictureDegree(source)
      }
    }else {
      if (Platform.OS === 'ios') {
        return ReadImageDataManager.readPictureDegree(Image.resolveAssetSource(source))
      }else{//安卓
        return ReadImageDataManager.readPictureDegree(Image.resolveAssetSource(source).uri)
      }
    }
  }

  /**
   * 压缩图片
   * @param params
   * {
   *    filePath:'', 图片路径
   *    threshold:200, 图片压缩阀值 单位kb
   * }
   * @returns {Promise}
   */
  static compression(params: object): Promise {
    if(params.filePath)
      params.filePath = params.filePath.replace("file://", "");
    return ReadImageDataManager.compression(params);
  }

  /**
   * 锐化
   * @param params
   * {
   *    filePath:'', 图片路径
   * }
   * @returns {Promise}
   */
  static sharpen(params: object): Promise {
    if(params.filePath)
      params.filePath = params.filePath.replace("file://", "");
    return ReadImageDataManager.sharpen(params);
  }

  /**
   * 对比度增强
   * @param params
   * {
   *    filePath:'', 图片路径
   * }
   * @returns {Promise}
   */
  static contrast(params: object): Promise {
    if(params.filePath)
      params.filePath = params.filePath.replace("file://", "");
    return ReadImageDataManager.contrast(params);
  }

}
